<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<title>Layui</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="../lib/layui/css/layui.css" media="all">
<style>
    #layui-laypage-1 .layui-laypage-limits {
        display: none;
    }
</style>
</head>
<body>
<!--缺陷管理列表页面-->
<div style="margin-bottom: 5px;">

    <!--新增按钮-->
    <div style="text-align:right;width:96.8%">
        <div class="layui-form-item">
            <a>
                <button id="add" onclick="flawadd()" class="layui-btn" style="margin-right:400px;background-color: #93D1FF">
                    <i class="layui-icon" >添加&#xe654;</i>
                </button>
            </a>
        </div>
    </div>
    <!--缺陷管理列表模块-->
    <table class="layui-table" lay-data="{width: 604,height:250, url:'/flaw/list', page:true,limit:3, id:'test'}"
           lay-filter="demo">
        <thead>
        <tr>
            <th lay-data="{field:'configValueName', width:200}">缺陷类型名称</th>
            <th lay-data="{field:'isStartStr', width:200}">状态（启用/未启用）</th>
            <th lay-data="{fixed: 'right', width:200, align:'center', toolbar: '#barDemo'}">操作</th>
        </tr>
        </thead>
    </table>

    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
</div>
<script src="../lib/layui/layui.js" charset="utf-8"></script>
<script src="../js/jquery.min.js" charset="utf-8"></script>
<script>
    layui.use(['table', 'layer', 'form', 'laypage', 'laydate'], function () {
        var table = layui.table //表格
            ,layer = layui.layer //弹层
            ,form = layui.form //form表单
        //监听工具条
        table.on('tool(demo)', function(obj){
            var data = obj.data;
            console.log("id:"+data.id)
            if(obj.event === 'del'){
                layer.confirm('真的删除么', function(index){
                    $.ajax({
                        type:"POST",
                        url:'/flaw/del?id='+data.id,
                        async: false, //改为同步请求
                        contentType:'application/json;charset=UTF-8',
                        dataType:'json',
                        success:function(data){
                            if(data){
                                obj.del();
                                layer.close(index);
                                layer.msg('删除成功', { icon: 6 });
                            }else{
                                layer.msg('删除失败', { icon: 2 });
                            }
                        },
                        error:function () {
                        }
                    });
                });
            } else if(obj.event === 'edit'){
                layer.open({
                    type: 2,
                    content: ["/flaw/flaw_edit?id="+data.id],   //添加页，后台controller转发到指定页
                    area: ["400px", "400px"],
                    title: ['修改缺陷类型'],
                    fixed: false,
                    shadeClose: true,
                    end: function () {  //刷新页面
                        table.reload('test', {
                            page: {
                                curr: 1 //重新从第 1 页开始
                            },
                            url: '/flaw/list', //后台做模糊搜索接口路径
                            method: 'post'
                        });
                    }
                })
            }
        });
        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });

    //添加
    function flawadd() {
        layui.use('layer', function () {
            layer.open({
                type: 2,
                content: ["/flaw/flaw_add"],   //添加页，后台controller转发到指定页
                area: ["400px", "400px"],
                title: ['添加缺陷类型'],
                fixed: false,
                //maxmin: true,
                shadeClose: true,
                end: function () {  //刷新页面
                    location.reload();
                }
            })
        })
    }


</script>

</body>
</html>